package NC18_顺时针旋转矩阵;

import java.util.*;

public class Solution {
    public int[][] rotateMatrix(int[][] mat, int n) {
        // write code here
        // 先对角线翻转
        for (int i = 0; i < n; i++){
            for (int j = 0; j < i; j++){
                int temp = mat[i][j];
                mat[i][j] = mat[j][i];
                mat[j][i] = temp;
            }
        }

        // 再左右翻转
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n / 2; j++){
                int temp = mat[i][j];
                 mat[i][j] = mat[i][n - j - 1];
                mat[i][n - j - 1] = temp;
            }
        }
        return mat;
    }
}